<!-- 充值 -->
<template>
  <el-dialog width="60%" :before-close="dataFormCancle" :title="'充值页面'" :close-on-click-modal="false"
    :visible.sync="visible">
    <el-descriptions class="margin-top" title="年卡信息" :column="3" border>
      <el-descriptions-item label="姓名">
        {{cardInfo.name}}
      </el-descriptions-item>
      <el-descriptions-item label="编号">
        {{cardInfo.num}}
      </el-descriptions-item>
      <el-descriptions-item label="性别">
        <dict-tag :options="dict.type.sys_user_sex" :value="cardInfo.sex" />
      </el-descriptions-item>
      <el-descriptions-item label="年龄">
        {{cardInfo.age}}
      </el-descriptions-item>
      <el-descriptions-item label="截止日期">
        {{cardInfo.endDate}}
      </el-descriptions-item>
    </el-descriptions>
    <el-descriptions style="margin-top: 20px;" class="margin-top" title="充值信息" :column="2"></el-descriptions>
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="充值金额" prop="money">
            <el-input v-model="dataForm.money" placeholder="充值金额"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系方式" prop="mobile">
            <el-input v-model="dataForm.mobile" placeholder="联系方式"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark">
            <el-input type="textarea" :rows="6" v-model="dataForm.remark" placeholder="备注"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dataFormCancle">取消</el-button>
      <el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {
    addOrUpdate
  } from "@/api/business/rechargerecord";
  import {
    page as getMembers
  } from '@/api/business/memberinfo'
  export default {
    dicts: ['sys_user_sex', 'sys_card_status'],
    data() {
      return {
        loading: false,
        title: '',
        visible: false,
        memberList: [],
        cardInfo: {
          name: '',
          sex: '',
          age: '',
          url: '',
          beginDate: '',
          endDate: '',
          createTime: '',
          status: '',
          count: '',
          remark: '',
          num: '',
          memberId: ''
        },
        dataForm: {
          id: '',
          cardId: '',
          mobile: '',
          money: 680,
          remark: '',
        },
        dataRule: {
          mobile: [{
              required: false,
              message: '手机号不能为空',
              trigger: 'blur'
            },
            {
              pattern: /^1(3|4|5|6|7|8|9)\d{9}$/,
              message: '手机号格式不对',
              trigger: 'blur'
            }
          ],
          money: [{
            required: true,
            message: '充值金额不能为空',
            trigger: 'blur'
          }],
          remark: [{
            required: false,
            message: '备注不能为空',
            trigger: 'blur'
          }],
        }
      }
    },
    created() {},
    methods: {
      init(record) {
        this.visible = true
        this.cardInfo = record
        this.dataForm.cardId = record.id
      },
      //关闭表单
      dataFormCancle() {
        this.visible = false
        this.loading = false
        this.$emit('refreshDataList')
      },
      // 表单提交
      dataFormSubmit() {
        this.loading = true;
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            addOrUpdate(this.dataForm).then(res => {
              this.visible = false
              this.loading = false
              this.$modal.msgSuccess("续费成功");
              this.$emit('refreshDataList')
            }).catch(res => {
              let _this = this
              setTimeout(() => {
                _this.loading = false
              }, 2000)
            })
          } else {
            this.loading = false
          }
        })
      }
    }
  }
</script>
